package org.zcl.controller;

import com.google.common.util.concurrent.RateLimiter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 速度限制器控制器
 *
 * @author zhuchenglin
 * @date 2022/09/01 17:02
 */
@Api(value = "/index", tags = {"指数控制器"})
@RestController
@RequestMapping("/index")
@Slf4j
public class RateLimiterController {

    /**
     * 限幅器
     */
    private final RateLimiter limiter = RateLimiter.create(2);


    /**
     * 速度限制器
     *
     * @return {@link String}
     */
    @ApiOperation(value = "速度限制器", notes = "速度限制器")
    @GetMapping(value = "/rateLimiter")
    public String RateLimiter() {
        limiter.acquire();
        log.info("RateLimiter do something");
        return "SUCCESS";
    }

}
